package com.Map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:Map回顾代码
 * User: cp
 * Date: 2023-12-19
 * Time: 11:45
 */
public class TestDemo3 {
    public static void main(String[] args) {
        HashMap<Integer,String> map = new HashMap();
        //添加
        map.put(1,"cp");
        map.put(2,"666");
        map.put(3,"hhh");

        //获取个数
        System.out.println(map.size());
        //遍历
        Set<Integer> keySet = map.keySet();
        for(Integer integer : keySet){
            String name = map.get(integer);
            System.out.println("k:"+integer +" "+"v:"+name);
        }

        //遍历
        map.put(3,"cpp");
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            Integer k = entry.getKey();
            String v = entry.getValue();
            System.out.println("k:"+k +" "+"v:"+v);
        }

        //包含
        System.out.println(map.containsKey(2)?"Y":"N");
        System.out.println(map.containsValue("cp") ? "Y" : "N");
    }
}
